package com.action;

import org.apache.struts2.ServletActionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.dao.impl.UserDao;
import com.entity.User;
import com.service.IUserService;
import com.tools.ExceptionShow;

public class UserAction {
	private IUserService userService;
	private User user;
	
	private static final Logger log = LoggerFactory.getLogger(UserAction.class);

	public void setUserService(IUserService userService) {
		this.userService = userService;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String create() {
		try {
			userService.save(user);
			log.info("注册成功:账号："+user.getName());
			ServletActionContext.getRequest().setAttribute("msg", "注册成功");
			return "success";
			
		} catch (Exception e) {
			log.error("注册失败:账号："+user.getName()+":"+ExceptionShow.getException(e));
			ServletActionContext.getRequest().setAttribute("msg", "注册失败");
			return "error";
		}
	}

}
